<?php
/**
 * 公共挂件 - 前台
 *
 * @author birdy <freebirdy@foxmail.com>
 * @link http://www.aiyuangong.com
 */

namespace app\index\widget;
use think\Cache;

class Index
{
    //平台左侧联系方式
    function contact()
    {
        $platform_contact = \Fields::getById("help");
        $view = new \think\View();
        return $view->fetch('widget/contact', ['platform_contact'=>$platform_contact]);
    }
    //平台底部常用解答
    function faq(){
        $article_class = Cache::tag('config')->get('home_faq');
        if(empty($article_class)){
            $show_article = ['help','seller','payment','after-sales','service','about'];
            $article_class_all = \Fields::getById('article');
            $article_class = [];
            foreach($article_class_all as $key => $val){
                if(in_array($val['tag'], $show_article)){
                    $article_class[$val['id']] = ['id'=>$val['id'], 'name'=>$val['name'], 'list'=>[]];
                }
            }
            $article_list	= rpc('common/common/lists',['article',['status'=>1,'isdelete'=>0,'type_id'=>['in',array_keys($article_class)]],['page'=>'0,30']]);
            if(!empty($article_list) && is_array($article_list)){
                foreach ($article_list as $key => $val){
                    $ac_id = $val['type_id'];
                    $article_class[$ac_id]['list'][$val['id']] = ['id'=>$val['id'], 'title'=>$val['title'], 'url'=>$val['url']];
                }
            }
            if(!empty($article_class)){
                //加入缓存
                Cache::tag('config')->set('home_faq', $article_class);
            }
        }
        $view = new \think\View();
        return $view->fetch('widget/faq', ['class_list'=>$article_class]);
    }
}
